package com.programmingteam.wallpaperslideshow.ui;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.programmingteam.wallpaperslideshow.Config;
import com.programmingteam.wallpaperslideshow.R;
import com.programmingteam.wallpaperslideshow.ui.fragments.DashboardFragment;

/**
 * Front-door {@link Activity} that displays high-level features the schedule
 * application offers to users. Depending on whether the device is a phone or an
 * Android 3.0+ tablet, different layouts will be used. For example, on a phone,
 * the primary content is a {@link DashboardFragment}, whereas on a tablet, both
 * a {@link DashboardFragment} and a {@link TagStreamFragment} are displayed.
 */
public class HomeActivity extends BaseActivity {
	private static final String TAG = "WallpaperSlideshow";
	
	// private TagStreamFragment mTagStreamFragment;
	// private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment;

	private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			Log.d(TAG, "HomeActivity - received broadcast");
		}
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		getActivityHelper().setupActionBar(null, 0);
	}

    @Override
    protected void onResume() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Config.Service.BROADCAST_ACTION_ON_DOWNLOADED);
        LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mReceiver, filter);
        super.onResume();
    }

    @Override
    protected void onPause() {
    	LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(mReceiver);
        super.onPause();
    }
	
	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);
		getActivityHelper().setupHomeActivity();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Here we create menus
		super.onCreateOptionsMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return super.onOptionsItemSelected(item);
	}
}
